//
//  ZYEmotionCell.swift
//  01-表情键盘
//
//  Created by 陈宗毅 on 15/12/28.
//  Copyright © 2015年 czy. All rights reserved.
//

import UIKit

class ZYEmotionCell: UICollectionViewCell {
    
    var emotion:ZYEmotion? {
        didSet{
            print("cell的模型\(emotion)")
            if let pngPath = emotion?.pngPath
            {
                // 有图片,设置图片,不能直接使用png,需要拼接完整地路径
                emotionButton.setImage(UIImage(contentsOfFile: pngPath), forState: UIControlState.Normal)
            }else {
                emotionButton.setImage(nil, forState: UIControlState.Normal)
            }
            emotionButton.setTitle(emotion?.emoji, forState: UIControlState.Normal)
            
            //显示删除按钮
            if emotion!.removeEmoticon {
                emotionButton.setImage(UIImage(named: "compose_emotion_delete_highlighted"), forState: UIControlState.Normal)
            
            }
        }
        
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
     override init(frame: CGRect) {
        super.init(frame: frame)
        
        prepareUI()
    }

    
    
    private func prepareUI(){
        
        contentView.addSubview(emotionButton)
        
        emotionButton.frame = CGRectInset(bounds, 3, 3)
        emotionButton.backgroundColor = UIColor.brownColor()
    
    }
    
    
    //MARK: - 懒加载
    /// 按钮，显示图片和emoji表情
    private lazy var emotionButton:UIButton = {
        let button = UIButton()
        
        button.titleLabel?.font = UIFont.systemFontOfSize(32)
        
        button.userInteractionEnabled = false
        
        return button
        }()
}
